﻿using Riba.MVVMSL;

namespace TestGUI
{
	public class Page3ViewModel : ViewModelBase
	{
		private int _calls;

		public RelayCommand CommandNotify { get; private set; }

		public Page3ViewModel()
		{
			ExchangeDataAvailable += Page3ViewModel_ExchangeDataAvailable;
			CommandNotify = new RelayCommand(OnCommandNotify) { IsEnabled = true };
		}

		void Page3ViewModel_ExchangeDataAvailable(object sender, ExchangeDataAvailableEventArgs e)
		{
			ExchangeDataDictionary["CurrentPage"] = typeof(Page3);
			PropertyChanged += Page3ViewModel_PropertyChanged;
		}

		void Page3ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			IsDirty = true;
		}

		private void OnCommandNotify(object commandParameter)
		{
			_calls++;

			var n = new Notifier.NotificationEventArgs("Notification from Page3ViewModel", string.Format("Aufruf {0} aus Page3ViewModel", _calls), CallbackFromMainPage);
			Notifier.RaiseNotify(n);
		}

		private void CallbackFromMainPage(object data)
		{
			RaiseShowMsgBox(new ShowMsgBoxEventArgs(string.Format("Callback data='{0}'", data), "Titel"));
		}
	}
}
